home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ddj1190.arc / FRANZ.ASC < prev    next >
Text File  |  1990-10-27  |  12KB  |  455 lines

  1. _PROGRAMMER TOOLS FOR ACTOR 3.0_
  2. by Marty Franz
  3.  
  4. [LISTING ONE]
  5.  
  6. /* ROLO.H */
  7.  
  8. /* Menu Constants */
  9. #define SEARCH          2000
  10.  
  11. #define PRIMARY         2011  /* Index popup */
  12. #define ALTERNATE       2012
  13.  
  14. #define NEXT            2020
  15. #define PREV            2030
  16. #define INSERT          2040
  17. #define UPDATE          2050
  18. #define DELETE          2060
  19. !!
  20.  
  21. /* Dialog Constants */
  22. #define PHONE           101
  23. #define PERSON          102
  24. #define COMPANY         103
  25. !!
  26.  
  27.  
  28. [LISTING TWO]
  29.  
  30. /* Additional methods required by WinTrieve Rolodex Browser sample app. */
  31.  
  32. now(String);!!
  33.  
  34. /* Returns a copy of the receiver from
  35.   which a blank characters have been removed. */
  36. Def removeBlanks(self | str)
  37. { str := "";
  38.   do(self,
  39.   {using(c) if c <> ' ' then str := str + asString(c) endif;
  40.   });
  41.   ^str;
  42. }
  43. !!
  44. now(class(CType))!!
  45.  
  46. /* Return a CType object by looking up it's name in type dictionaries. Same as
  47.    findType method except does no error checking. */
  48. Def getType(self, tName)
  49. { ^$CTypes[tName] cor $UserTypes[tName];
  50. }
  51. !!
  52.  
  53.  
  54. [LISTING THREE]
  55.  
  56. /* Rolodex browser. */!!
  57.  
  58. inherit(Application, #RoloApp, nil, 2, nil)!!
  59.  
  60. now(class(RoloApp))!!
  61.  
  62. /* Remove unnecessary classes. */
  63. Def removeExtra(self)
  64. { do(#(EditWindow WinEllipse WinPolygon StopWatch
  65.        Control FileDialog ReplaceDialog RelFile),
  66.   {using(g) removeGlobal(self, g);
  67.   });
  68. }
  69. !!
  70.  
  71. now(RoloApp)!!
  72.  
  73. /* Startup the Rolodex browser. */
  74. Def init(self, cmdStr)
  75. { init(self:ancestor, cmdStr);
  76.   mainWindow := newMain(RoloWindow, nil, "Rolodex Browser", nil);
  77.   show(mainWindow, CmdShow);
  78.   if not(createDB(mainWindow))
  79.   then close(mainWindow);
  80.   endif;
  81. }
  82. !!
  83.  
  84. /* Class Initialization */
  85.  
  86.  
  87. [LISTING FOUR]
  88.  
  89. /* A Rolodex file. */!!
  90.  
  91. inherit(IsamFile, #RoloFile, nil, 2, nil)!!
  92.  
  93. now(RoloFileClass)!!
  94.  
  95. now(RoloFile)!!
  96.  
  97. /* Init Rolodex file record type and key defs. */
  98. Def init(self)
  99. { init(self:ancestor);
  100.   def(UserType, #rolo, #(
  101.     char    phone       30
  102.     char    person      30
  103.     char    company     30
  104.   ));
  105.   setRecType(self, #rolo);
  106.   addKeyDef(self, #primary, #NODUPS, #phone);
  107.   addKeyDef(self, #person, #DUPS, #person);
  108. }!!
  109.  
  110.  
  111. [LISTING FIVE]
  112.  
  113. /* Main window of Rolodex ISAM file browser. */!!
  114.  
  115. inherit(TextWindow, #RoloWindow, #(keysDict  /* Dictionary of keys */
  116. roloDB    /* ISAM manager */
  117. roloTable /* ISAM rolodex file */), 2, nil)!!
  118.  
  119. now(class(RoloWindow))!!
  120.  
  121. now(RoloWindow)!!
  122.  
  123. /* Initiate a session with the ISAM manager. Create the ISAM file. */
  124. Def createDB(self)
  125. { roloDB := new(IsamManager);
  126.   openManager(roloDB);
  127.   if checkError(roloDB)
  128.   then destroy(roloDB);
  129.     ^roloDB := nil;
  130.   endif;
  131.   roloTable := new(RoloFile);
  132.   setFilename(roloTable, "rolo");
  133.   setManager(roloTable, roloDB);
  134.   create(roloTable, ISINOUT + ISMANULOCK);
  135.   if checkError(roloTable)
  136.   then destroy(roloTable);
  137.     ^roloTable := nil;
  138.   endif;
  139. }
  140. !!
  141. /*  Handles input dialog processing for obtaining search title. Returns title 
  142.    or nil if user cancels. */
  143. Def getPerson(self | id title)
  144. { id := new(InputDialog, "Person Key", "Person:", "");
  145.   loop
  146.   while runModal(id, INPUT_BOX, self) = IDOK
  147.     title := leftJustify(getText(id));
  148.     if size(title) > 0
  149.     then ^title;
  150.     endif;
  151.   endLoop;
  152.   ^nil;
  153. }
  154. !!
  155. /* Handles input dialog processing for obtaining phone number. Returns phone 
  156.    number or nil if user cancels. */
  157. Def getPhone(self | id str val)
  158. { id := new(InputDialog, "Primary Key", "Phone:", "");
  159.   loop
  160.   while runModal(id, INPUT_BOX, self) = IDOK
  161.     str := removeBlanks(getText(id));
  162.     if size(str) > 0 cand (val := asInt(str, 10))
  163.     then ^val;
  164.     endif;
  165.   endLoop;
  166.   ^nil;
  167. }
  168. !!
  169. /* Validate record dialog input. If ok, returns dictionary of input field 
  170.   values. If error input field, displays error box and returns nil. */
  171. Def validateInput(self, cVals | input)
  172. { input := new(Dictionary, 10); /* Validate input. */
  173.   input[#phone] := leftJustify(removeBlanks(cVals[PHONE]));
  174.   if size(input[#phone]) = 0
  175.   then errorBox(caption, "Invalid Phone field.");
  176.   else input[#person] := leftJustify(cVals[PERSON]);
  177.     if size(input[#person]) = 0
  178.     then errorBox(caption, "Invalid Person field.");
  179.     else input[#company] := leftJustify(cVals[COMPANY]);
  180.       if size(input[#company]) = 0
  181.       then errorBox(caption, "Invalid Company field.");
  182.       else ^input
  183.       endif;
  184.     endif;
  185.   endif;
  186.   ^nil;
  187. } !!
  188. /* Close the database. */
  189. Def closeDB(self)
  190. { if roloTable
  191.   then close(roloTable);
  192.     destroy(roloTable);
  193.     roloTable := nil;
  194.   endif;
  195.   if roloDB
  196.   then closeManager(roloDB);
  197.     destroy(roloDB);
  198.     roloDB := nil;
  199.   endif;
  200. }
  201. !!
  202. /* Closing the window so close the database. */
  203. Def shouldClose(self)
  204. { closeDB(self);
  205. }
  206. !!
  207. /* Initiate a session with the ISAM manager. */
  208. Def openDB(self)
  209. { roloDB := new(IsamManager);
  210.   openManager(roloDB);
  211.   if checkError(roloDB)
  212.   then destroy(roloDB);
  213.     ^roloDB := nil;
  214.   endif;
  215.   roloTable := new(RoloFile);
  216.   setFilename(roloTable, "rolo");
  217.   setManager(roloTable, roloDB);
  218.   open(roloTable, ISINOUT + ISMANULOCK);
  219.   if checkError(roloTable)
  220.   then destroy(roloTable);
  221.     ^roloTable := nil;
  222.   endif;
  223. }
  224. !!
  225. /* Display the current record in the window. */
  226. Def printRecord(self)
  227. { cls(self);
  228.   printString(self, "Phone:     ");
  229.   printString(self, asString(getField(roloTable, #phone)));
  230.   eol(self);
  231.   printString(self, "Person:    ");
  232.   printString(self, asString(getField(roloTable, #person)));
  233.   eol(self);
  234.   printString(self, "Company:    ");
  235.   printString(self, asString(getField(roloTable, #company)));
  236.   eol(self);
  237. }
  238. !!
  239. /* Build a record dialog. */
  240. Def recDlg(self, dPhone, dPerson, dCompany | D)
  241. { D := new(DialogDesign);
  242.   setSize(D, 8@8, 185@120);
  243.   /*
  244.   addItem(D, newStatic(DlgItem, "Phone:", 100, 5@10, 40@10, 0));
  245.   addItem(D, newEdit(DlgItem, dPhone, PHONE, 50@10, 35@12, 0));
  246.   addItem(D, newStatic(DlgItem, "Person:", 100, 5@25, 40@10, 0));
  247.   addItem(D, newEdit(DlgItem, dPerson, PERSON, 50@25, 125@12, 0));
  248.   addItem(D, newStatic(DlgItem, "Company:", 100, 5@40, 40@10, 0));
  249.   addItem(D, newEdit(DlgItem, dCompany, COMPANY, 50@40, 35@12, 0));
  250.   */
  251.   addItem(D, newStatic(DlgItem, "Phone:", 100, 5@10, 40@10, 0));
  252.   addItem(D, newEdit(DlgItem, dPhone, PHONE, 50@10, 125@12, 0));
  253.   addItem(D, newStatic(DlgItem, "Person:", 100, 5@25, 40@10, 0));
  254.   addItem(D, newEdit(DlgItem, dPerson, PERSON, 50@25, 125@12, 0));
  255.   addItem(D, newStatic(DlgItem, "Company:", 100, 5@40, 40@10, 0));
  256.   addItem(D, newEdit(DlgItem, dCompany, COMPANY, 50@40, 125@12, 0));
  257.   addItem(D, newButton(DlgItem, "Cancel", IDCANCEL, 115@95, 40@14, 0));
  258.   ^D;
  259. }
  260. !!
  261. /* Search for a record based on current index order. */
  262. Def searchRec(self, wp | val)
  263. { select
  264.     case currentIndex(roloTable) = #primary
  265.     is val := getPhone(self);
  266.       if not(val)
  267.       then ^nil;
  268.       endif;
  269.       putField(roloTable, val, #phone);
  270.     endCase
  271.     case currentIndex(roloTable) = #person
  272.     is val := getPerson(self);
  273.       if not(val)
  274.       then ^nil;
  275.       endif;
  276.       putField(roloTable, val, #person);
  277.     endCase
  278.   endSelect;
  279.   if not(read(roloTable, ISEQUAL))
  280.   then checkError(roloTable);
  281.     ^nil;
  282.   endif;
  283.   printRecord(self);
  284. }
  285. !!
  286. /* Read the previous record and display it. */
  287. Def prevRec(self, wp)
  288. { if read(roloTable, ISPREV)
  289.   then printRecord(self);
  290.   else checkError(roloTable);
  291.     cls(self);
  292.   endif;
  293. }
  294. !!
  295. /* Read the next record and display it. */
  296. Def nextRec(self, wp)
  297. { if read(roloTable, ISNEXT)
  298.   then printRecord(self);
  299.   else checkError(roloTable);
  300.     cls(self);
  301.   endif;
  302. }
  303. !!
  304. /* Insert a record. */
  305. Def insertRec(self, wp | rDlg cVals iVals)
  306. { rDlg := recDlg(self, "", "", "");
  307.   loop
  308.   while runModal(rDlg, nil, self) <> 0
  309.     cVals := controlValues(rDlg);
  310.     if iVals := validateInput(self, cVals)
  311.     then putField(roloTable, iVals[#phone], #phone);
  312.       putField(roloTable, iVals[#person], #person);
  313.       putField(roloTable, iVals[#company], #company);
  314.       if not(insertCurrent(roloTable))
  315.       then checkError(roloTable);
  316.       else printRecord(self);
  317.       endif;
  318.       ^self;
  319.     endif;
  320.     rDlg := recDlg(self, cVals[PHONE], cVals[PERSON], cVals[COMPANY]);
  321.   endLoop;
  322. }!!
  323. /* Change to selected index and display first record in new index ordering. */
  324. Def changeIndex(self, wp | key oldKey)
  325. { key := keyAt(keysDict, wp);
  326.   oldKey := currentIndex(roloTable);
  327.   if key = oldKey
  328.   then ^self;
  329.   endif;
  330.   if selectRecord(roloTable, key, 0, ISFIRST)
  331.   then read(roloTable, ISNEXT);
  332.     unCheckMenuItem(menu, keysDict[oldKey]);
  333.     checkMenuItem(menu, wp);
  334.   endif;
  335.   if not(checkError(roloTable))
  336.   then printRecord(self);
  337.   endif;
  338. }
  339. !!
  340. /* Delete the current record. */
  341. Def deleteRec(self, wp)
  342. { if not(deleteCurrent(roloTable))
  343.   then checkError(roloTable);
  344.   else cls(self);
  345.   endif;
  346. }
  347. !!
  348. /* Update a record. */
  349. Def updateRec(self, wp | rDlg cVals iVals)
  350. { if not(read(roloTable, ISCURR))
  351.   then checkError(roloTable);
  352.     ^self;
  353.   endif;
  354.   rDlg := recDlg(self,
  355.     asString(getField(roloTable, #phone)),
  356.     getField(roloTable, #person),
  357.     asString(getField(roloTable, #company)));
  358.   loop
  359.   while runModal(rDlg, nil, self) <> 0
  360.     cVals := controlValues(rDlg);
  361.     if iVals := validateInput(self, cVals)
  362.     then putField(roloTable, iVals[#phone], #phone);
  363.       putField(roloTable, iVals[#person], #person);
  364.       putField(roloTable, iVals[#company], #company);
  365.       if not(updateCurrent(roloTable))
  366.       then checkError(roloTable);
  367.       else printRecord(self);
  368.       endif;
  369.       ^self;
  370.     endif;
  371.     rDlg := recDlg(self, cVals[PHONE], cVals[PERSON], cVals[COMPANY]);
  372.   endLoop;
  373. }!!
  374. /* Respond to the menu events.
  375.   The wp argument gives the selected menu ID.
  376.   Get a message symbol from the menu object. */
  377. Def command(self, wp, lp | msg)
  378. { if msg := action(menu, wp)
  379.   then ^perform(self, wp, msg)
  380.   endif;
  381. }!!
  382. /* Setup the menu bar. */
  383. Def createMenu(self)
  384. { createMenu(self:ancestor);
  385.   menu := init(new(Menu));
  386.   setHandle(menu, hMenu);
  387.   topMenu(menu, "&Search!", SEARCH, #searchRec);
  388.   keysDict := new(OrderedDictionary, 4);
  389.   keysDict[#primary] := PRIMARY;
  390.   keysDict[#person] := ALTERNATE;
  391.   popupMenu(menu, "&Index",
  392.     tuple("phone", "person"),
  393.     tuple(PRIMARY, ALTERNATE), #changeIndex);
  394.   checkMenuItem(menu, PRIMARY);
  395.   topMenu(menu, "&Next!", NEXT, #nextRec);
  396.   topMenu(menu, "&Prev!", PREV, #prevRec);
  397.   topMenu(menu, "&Insert!", INSERT, #insertRec);
  398.   topMenu(menu, "&Update!", UPDATE, #updateRec);
  399.   topMenu(menu, "&Delete!", DELETE, #deleteRec);
  400.   drawMenu(self);
  401. }
  402. !!
  403. /* Initialize the window. Create menu and About to control menu. */
  404. Def init(self)
  405. { init(self:ancestor);
  406.   createMenu(self);
  407.   addAbout(self);
  408. }
  409. !!
  410.  
  411. /* Class Initialization */
  412.  
  413.  
  414. [ROLO.LOD]
  415.  
  416. /* Load file for WinTrieve Rolodex Browser.  You must load
  417.    ISAM.LOD file before loading these files. */
  418.  
  419. LoadFiles := tuple(
  420.   "classes\menu.cls",           /* dynamic menu support */
  421.  
  422.   "res\control.h",              /* dynamic dialog support */
  423.   "classes\dlgitem.cls",
  424.   "classes\dialogde.cls",
  425.  
  426.   "res\rolo.h",                 /* rolo Browser support */
  427.   "classes\rolofile.cls",
  428.   "classes\rolowind.cls",
  429.   "classes\roloapp.cls",
  430.   "act\rolo.act"
  431. )!!
  432.  
  433. printLine("");!!
  434. printLine("Use load() to load WinTrieve Rolodex Browser");!!
  435.  
  436.  
  437. [EXAMPLE 1]
  438.  
  439. /* Build a record dialog. */
  440. Def recDlg(self, dPhone, dPerson, dCompany | D)
  441. { D := new(DialogDesign);
  442.   setSize(D, 8@8, 185@120);
  443.   addItem(D, newStatic(DlgItem, "Phone:", 100, 5@10, 40@10, 0));
  444.   addItem(D, newEdit(DlgItem, dPhone, PHONE, 50@10, 35@12, 0));
  445.   addItem(D, newStatic(DlgItem, "Person:", 100, 5@25, 40@10, 0));
  446.   addItem(D, newEdit(DlgItem, dPerson, PERSON, 50@25, 125@12, 0));
  447.   addItem(D, newStatic(DlgItem, "Company:", 100, 5@40, 40@10, 0));
  448.   addItem(D, newEdit(DlgItem, dCompany, dCompany, 50@40, 35@12, 0));
  449.   addItem(D, newButton(DlgItem, "Cancel", IDCANCEL, 115@95, 40@14, 0));
  450.   ^D;
  451. }
  452.  
  453.  
  454.  
  455.